package com.idreems.model;

import java.util.LinkedList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import android.text.TextUtils;

import com.huewu.pla.pinterest.internal.ImageWrapper;

public class WeiboHumer extends JionServerData {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public WeiboHumer() {
        mTitle = "微博笑典";
        mUrl = "http://www.xh888.com/webservicestest/ajax/GetListByIdSort.ashx?webtypeid=1&count="+kArticlesPerPage;
    }
    @Override
    public String url(int page) {
        if(page<=0)
        {
            page = 1;
        }
        mUrl = "http://www.xh888.com/webservicestest/ajax/GetListByIdSort.ashx?webtypeid=1&count="+page*kArticlesPerPage;
        return mUrl;
    }
    @Override
    public List<ImageWrapper> decode(String data) {
        List<ImageWrapper> timeline = new LinkedList<ImageWrapper>();
        if (TextUtils.isEmpty(data)) {
            return timeline;
        }
        try {
            mDescription = "JokeContent";
            mThumbnailUrl = "ImgUrl";

            JSONArray jTimeline = new JSONArray(data);
            for (int i = 0; i < jTimeline.length(); i++) {
                JSONObject element = jTimeline.getJSONObject(i);
                ImageWrapper wrapper = new ImageWrapper();

                wrapper.description = element.getString(mDescription);
                wrapper.url = element.getString(mThumbnailUrl);
                wrapper.largeUrl = wrapper.url;
                wrapper.id = i;
                timeline.add(wrapper);
            }
        } catch (Exception e) {
        }
        return timeline;
    }
}
